import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/controller/reports.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/grids/singleHomeworkDataGrid.dart';
import 'package:ichinesereader/widgets/layouts/customAppBar.dart';

// ignore: must_be_immutable
class HomeworkProgress extends StatefulWidget {
  HomeworkProgress({Key? key, required this.name, required this.id})
      : super(key: key);
  static const String routeName = '/teacher/reports/homeworkprogress';
  String id;
  String name;

  @override
  _HomeworkProgress createState() => _HomeworkProgress();
}

class _HomeworkProgress extends State<HomeworkProgress> {
  final ReportsController _reportsController = Get.put(ReportsController());
  var box = Hive.box('appconfig');

  @override
  void initState() {
    var classId = box.get(CacheManagerKey['currentclass'].toString());
    Future.delayed(Duration(milliseconds: 100), () {
      _reportsController.fetchSingleAssingmentRecord(classId, widget.id);
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    Log.debug('build teacher assignment progress');

    return Scaffold(
      appBar: CustomAppBar(title: widget.name),
      body: Padding(
        padding: const EdgeInsets.all(1.0),
        child: Center(
          child: Column(
            children: [
              Expanded(
                child: _reportsController.obx(
                  (data) {
                    return SignleHomeworkDataGrid(
                        _reportsController.singleAssignmentData, widget.id);
                  },
                  onEmpty: Text('Data not available ...'.tr),
                  onLoading: Container(),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
